<?php

/**
 * Context上下文
 * Class CashRebate
 */
class CashContext
{
    private $cash_instance;

    public function __construct($type)
    {
        switch ($type) {
            case 1:
                $this->cash_instance = new CashCommon();
                break;
            case 2:// 打折
                $this->cash_instance = new CashRebate(0.8);
                break;
            case 3:// 返现
                $this->cash_instance = new CashReturn(100, 20);
                break;
            default:
                throw new Exception('不支持类型');
        }
    }

    public function getResult($money)
    {
        return $this->cash_instance->acceptMoney($money);
    }
}